//import 'dart:html';

import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/public_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'action.dart';
import 'state.dart';

const APPBAR_SCROLL_OFFSET = 200;
List signList = [
  {'title': '第1天', 'img': 'assets/images/public_module/public_laxin_rank1.png'},
  {'title': '第2天', 'img': 'assets/images/public_module/public_laxin_rank3.png'},
  {'title': '第3天', 'img': 'assets/images/public_module/public_laxin_rank2.png'},
  {'title': '第4天', 'img': 'assets/images/public_module/public_laxin_rank3.png'},
  {'title': '第5天', 'img': 'assets/images/public_module/public_laxin_rank1.png'},
  {'title': '第6天', 'img': 'assets/images/public_module/public_laxin_rank2.png'},
  {'title': '第7天', 'img': 'assets/images/public_module/public_laxin_rank3.png'},
];
List gridViewList = [
  '第一天',
  '第二天',
  '第三天',
  '第四天',
  '第五天',
  '第六天',
  '第七天',
  '第一天',
  '第二天',
  '第三天',
  '第四天',
  '第五天',
  '第六天',
  '第七天',
];

Widget buildView(TaskState state, Dispatch dispatch, ViewService viewService) {
  //返回上一页键盘保证不越界：上一页需要用scroll的组件包裹(溢出原因：本页面的组件占有本业空间足够多，没有留下合适的键盘使用空间)
  _onScroll(offset) {
    double alpha = offset / APPBAR_SCROLL_OFFSET;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    dispatch(TaskActionCreator.upAppBarAlpha(alpha));
  }

  return Scaffold(
    backgroundColor: Color.fromRGBO(248, 248, 248, 1),
    body: Stack(
      children: <Widget>[
        NotificationListener(
          onNotification: (scrollNotification) {
            if (scrollNotification is ScrollUpdateNotification &&
                scrollNotification.depth == 0) {
              //滚动且是列表滚动的时候
              _onScroll(scrollNotification.metrics.pixels);
            }
            return false; //onNotification是个方法，需要返回值 。返回true时多个列表导致出现混乱，false找到顶级父类统一管理
          },
          child: ListView(
            padding: EdgeInsets.only(top: 0),
            children: <Widget>[
              _headView(state, dispatch, viewService),
              _taskView(),
              _circleView(),
              _exchangeView(),
              _moneyView(state, dispatch, viewService),
               Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(left: 10, top: 15, bottom: 15),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Colors.amber[100], Colors.amber[50]],
                      ),
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: Text(
                      '每日推荐',
                      style: TextStyle(
                        fontSize: 17,
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ],
              ),
              _recommendView(state, dispatch, viewService),
            ],
          ),
        ),
        Opacity(
          opacity: state.appBarAlpha,
          child: Container(
            color: Colors.white,
            width:ScreenUtil.screenWidth ,
            height:ScreenUtil.statusBarHeight + 44 ,
            padding: EdgeInsets.only(
              top: ScreenUtil.statusBarHeight + 9,),
            child: Stack(
              alignment: AlignmentDirectional.center,
              children: [
                Positioned(
                  left: setWidth(16),child: GestureDetector(
                  onTap: () {},
                  child: Container(
                    child: Image.asset(
                      'assets/images/public_module/public_back.png',
                      width: setWidth(22),
                      color: Colors.black,
                    ),
                  ),
                ),),
                Text(
                  '任务中心',
                  style: TextStyle(
                    fontSize: setSp(16),
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                  ),),
              ],
            ) ,
          ),
        ),
      ],
    ),
  );
}

///头部
Widget _headView(TaskState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    decoration: BoxDecoration(
      image: DecorationImage(
        image: AssetImage('assets/images/user_center/task_head_bg.png'),
        fit: BoxFit.fitWidth,
          alignment:Alignment.topCenter
      ),
    ),
    child: Column(
     // crossAxisAlignment:CrossAxisAlignment.start,
      children: [
        Container(
          width:ScreenUtil.screenWidth ,
          margin: EdgeInsets.only(
              top: ScreenUtil.statusBarHeight + 9,),
          child: Stack(
            alignment: AlignmentDirectional.center,
            children: [
              Positioned(
                left: setWidth(16),child: GestureDetector(
                onTap: () {},
                child: Container(
                  child: Image.asset(
                    'assets/images/public_module/public_back.png',
                    width: setWidth(22),
                  ),
                ),
              ),),
             Text(
                  '任务中心',
                  style: TextStyle(
                    fontSize: setSp(16),
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),),
            ],
          ) ,
        ),
        SizedBox(
          height: setHeight(22),
        ),
        Container(
          padding: EdgeInsets.only(left: setWidth(20)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '我的花币',
                    style: TextStyle(
                      fontSize: setSp(15),
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  Row(
                    children: [
                      Text(
                        '1000000',
                        style: TextStyle(
                          fontSize: setSp(40),
                          color: Colors.white,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      SizedBox(
                        width: setWidth(4),
                      ),
                      GestureDetector(
                        onTap: () {},
                        child: Container(
                          alignment: Alignment.center,
                          width: setWidth(77),
                          height: setHeight(25),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(Radius.circular(setWidth(25))),
                            border:Border.all(width: 1, color: Colors.white),
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                '积分明细',
                                style: TextStyle(
                                  fontSize: setSp(11),
                                  color: Colors.white,
                                ),
                              ),
                              SizedBox(
                                width: setWidth(5),
                              ),
                              Image.asset(
                                'assets/images/user_center/task_right.png',
                                width: setWidth(4),
                              )
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
              GestureDetector(
                onTap: () {},
                child: Container(
                  width: 50,
                  height: 27,
                  alignment: Alignment.center,
                  decoration: new BoxDecoration(
                    color: Color.fromRGBO(0, 0, 0, .3),
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(27),
                        bottomLeft: Radius.circular(27)),
                  ),
                  child: Text(
                    '规则',
                    style: TextStyle(
                      fontSize: 12,
                      color: Colors.white,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.fromLTRB(10, 30, 10, 0),
          padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(10)),
            color: Colors.white,
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 0),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Colors.amber[100], Colors.amber[50]],
                      ),
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child:
                    Text(
                      '签到领花币',
                      style: TextStyle(
                        fontSize: 17,
                        color: Colors.black,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Row(
                    children: [
                      Text(
                        '签到提醒',
                        style: TextStyle(
                          fontSize: 13,
                          color: Colors.grey,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      Transform.scale(
                        scale: 0.7,
                        child: Container(
                          width: 50,
                          height: 20,
                          child: CupertinoSwitch(
                            value: state.valueSwitch,
                            onChanged: (newValue) {
                              dispatch(TaskActionCreator.upSwitch(newValue));
                            },
                            activeColor: Colors.red,
                          ),
                        ),
                      ),
                    ],
                  )
                ],
              ),
              SizedBox(
                height: 5,
              ),
              Text(
                '连续签到可获得额外奖励',
                style: TextStyle(
                  fontSize: 15,
                  color: Colors.grey,
                ),
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: signList
                    .asMap()
                    .map((index, value) {
                      return MapEntry(
                        index,
                        InkWell(
                          onTap: () {},
                          child: Container(
                            padding: EdgeInsets.symmetric(
                                horizontal: 5, vertical: 10),
                            decoration: BoxDecoration(
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5)),
                              color: Colors.grey[100],
                            ),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  value['title'],
                                  style: TextStyle(
                                    fontSize: 11,
                                    color: Colors.black,
                                  ),
                                ),
                                SizedBox(
                                  height: 5,
                                ),
                                Image.asset(
                                  value['img'],
                                  width: 25,
                                  height: 25,
                                ),
                              ],
                            ),
                          ),
                        ),
                      );
                    })
                    .values
                    .toList(),
              ),
              SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  InkWell(
                    onTap: () {},
                    child: Container(
                      width: 200,
                      height: 50,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                            colors: [Colors.orange[700], Colors.red]),
                        borderRadius: BorderRadius.circular(50),
                      ),
                      child: Text.rich(
                        TextSpan(
                          children: [
                            TextSpan(
                                text: "立即签到+10",
                                style: TextStyle(
                                    color: Colors.white, fontSize: 17)),
                            WidgetSpan(
                                child: Icon(
                              Icons.filter_tilt_shift,
                              color: Colors.orange,
                              size: 18,
                            )),
                          ],
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

///任务
Widget _taskView() {
  return Container(
    margin: EdgeInsets.symmetric(horizontal: 10, vertical: 15),
    padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: EdgeInsets.only(top: 0),
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Colors.amber[100], Colors.amber[50]],
            ),
            borderRadius: BorderRadius.circular(8),
          ),
          child: Text(
            '签到领花币',
            style: TextStyle(
              fontSize: 17,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        _taskItem('assets/images/user_center/medingdan.png', '添加导师微信', '+10',
            "手把手教你玩转券后价", "去添加"),
        _taskItem('assets/images/user_center/mefensi.png', '完善个人信息', '+50',
            "享更顺购物体验", "去完成"),
        SizedBox(
          height: 10,
        ),
        Container(
          margin: EdgeInsets.only(top: 0),
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Colors.amber[100], Colors.amber[50]],
            ),
            borderRadius: BorderRadius.circular(8),
          ),
          child: Text(
            '日常任务',
            style: TextStyle(
              fontSize: 17,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        _taskItem('assets/images/user_center/medingdan.png', '邀请一个新粉丝(0/3)',
            '+300', "邀请好友注册", "去邀请"),
        _taskItem('assets/images/user_center/mefensi.png', '浏览特价版淘宝', '+10',
            "抢一元好物", "去完成"),
        _taskItem('assets/images/user_center/medingdan.png', '邀请好友首次下单(0/3)',
            '+1000', "好友首次下单成功", "去邀请"),
        _taskItem('assets/images/user_center/mefensi.png', '唤醒老用户下单', '+500',
            "邀请沉睡粉丝下单", "去下单"),
        SizedBox(
          height: 10,
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              '查看更多任务',
              style: TextStyle(
                fontSize: 15,
                color: Colors.grey,
              ),
            ),
            SizedBox(
              width: 5,
            ),
            Image.asset(
              'assets/images/auth_module/login_arrow_down.png',
              width: 14,
              height: 14,
            ),
          ],
        ),
      ],
    ),
  );
}

Widget _taskItem(
    String img, String title1, String title2, String title3, String title4) {
  return Container(
    margin: EdgeInsets.symmetric(vertical: 15),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Image.asset(
          img,
          width: 50,
          height: 50,
        ),
        SizedBox(
          width: 10,
        ),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Flexible(
                    child: Text(
                      title1,
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 17,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Container(
                    alignment: Alignment.center,
                    child: Text(
                      "$title2",
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 17,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Icon(
                    Icons.filter_tilt_shift,
                    color: Colors.orange,
                    size: 18,
                  ),
                ],
              ),
              SizedBox(
                height: 5,
              ),
              Text(
                title3,
                style: TextStyle(
                  fontSize: 15,
                  color: Colors.grey,
                ),
              ),
            ],
          ),
        ),
        InkWell(
          onTap: () {},
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 20),
            height: 36,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              gradient:
                  LinearGradient(colors: [Colors.orange[700], Colors.red]),
              borderRadius: BorderRadius.circular(36),
            ),
            child: Text(
              title4,
              style: TextStyle(
                fontSize: 15,
                color: Colors.white,
              ),
            ),
          ),
        ),
      ],
    ),
  );
}

///幸运大转盘
Widget _circleView() {
  return Container(
    margin: EdgeInsets.symmetric(horizontal: 10),
    padding: EdgeInsets.symmetric(vertical: 15),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          padding: EdgeInsets.symmetric(horizontal: 15),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                margin: EdgeInsets.only(top: 0),
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [Colors.amber[100], Colors.amber[50]],
                  ),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Text(
                  '幸运大转盘',
                  style: TextStyle(
                    fontSize: 17,
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 0, right: 10),
                height: 27,
                decoration: BoxDecoration(
                  color: Colors.grey[100],
                  borderRadius: BorderRadius.circular(27),
                ),
                child: Row(
                  children: [
                    Icon(
                      Icons.filter_tilt_shift,
                      color: Colors.orange,
                      size: 27,
                    ),
                    Text.rich(
                      TextSpan(
                        children: [
                          TextSpan(
                              text: " 清***抽中",
                              style: TextStyle(
                                color: Colors.orangeAccent,
                                fontSize: 13,
                              )),
                          TextSpan(
                            text: "500元现金红包",
                            style: TextStyle(color: Colors.red, fontSize: 13),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
        Container(
          height: 100,
          padding: EdgeInsets.symmetric(horizontal: 15),
          margin: EdgeInsets.only(top: 20, bottom: 25),
          color: Colors.white,
          child: ListView.separated(
            scrollDirection: Axis.horizontal,
            itemCount: 50,
            separatorBuilder: (BuildContext context, int index) {
              return Container(
                width: 10,
              );
            },
            itemBuilder: (context, index) {
              return _circleItem(index);
            },
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(horizontal: 15),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              InkWell(
                onTap: () {},
                child: Container(
                  width: 200,
                  height: 50,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                        colors: [Colors.orange[700], Colors.red]),
                    borderRadius: BorderRadius.circular(50),
                  ),
                  child: Text.rich(
                    TextSpan(
                      children: [
                        WidgetSpan(
                          child: Icon(
                            Icons.filter_tilt_shift,
                            color: Colors.orange,
                            size: 18,
                          ),
                        ),
                        TextSpan(
                            text: " 50免费抽",
                            style:
                                TextStyle(color: Colors.white, fontSize: 17)),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget _circleItem(int index) {
  return Container(
    width: 100,
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.grey[100],
    ),
    alignment: Alignment.center,
    child: Image.network(
      index % 2 == 0
          ? 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg01.e23.cn%2F2018%2F0212%2F20180212034631201.jpg&refer=http%3A%2F%2Fimg01.e23.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625907419&t=3ce6d1fbe0a21edc4bdae4f3f2a3aff0'
          : 'https://pics7.baidu.com/feed/241f95cad1c8a78621f9b8d43e8a7b3872cf50a6.jpeg?token=1a545bc4f1bb78b39a5a7a8e1a5d46b7&s=1088357AC5F513984FB9F055010010E3',
      width: 70,
      height: 70,
      fit: BoxFit.cover,
    ),
  );
}

//花币兑换
Widget _exchangeView() {
  return Container(
    margin: EdgeInsets.symmetric(horizontal: 10, vertical: 15),
    padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Container(
              margin: EdgeInsets.only(top: 0),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [Colors.amber[100], Colors.amber[50]],
                ),
                borderRadius: BorderRadius.circular(8),
              ),
              child: Text(
                '签到领花币',
                style: TextStyle(
                  fontSize: 17,
                  color: Colors.black,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            GestureDetector(
              onTap: () {},
              child: Text.rich(
                TextSpan(
                  children: [
                    TextSpan(
                        text: "更多",
                        style: TextStyle(color: Colors.black, fontSize: 15)),
                    WidgetSpan(
                        child: Icon(
                      Icons.chevron_right,
                      color: Colors.black,
                      size: 17,
                    )),
                  ],
                ),
              ),
            )
          ],
        ),
        Container(
          height: 155,
          margin: EdgeInsets.only(top: 20),
          color: Colors.white,
          child: ListView.separated(
            scrollDirection: Axis.horizontal,
            itemCount: 50,
            separatorBuilder: (BuildContext context, int index) {
              return Container(
                width: 10,
              );
            },
            itemBuilder: (context, index) {
              return _exchangeItem(index);
            },
          ),
        ),
      ],
    ),
  );
}

Widget _exchangeItem(int index) {
  return GestureDetector(
    onTap: () {},
    child: Container(
      width: 100,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(8),
            child: Image.network(
              'https://img.alicdn.com/bao/uploaded/i1/389649927/O1CN016KZY2H2NCcQR8JxMw_!!389649927.jpg',
              width: 100,
              height: 100,
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            height: 5,
          ),
          Text(
            '券后价，夏季必备物品',
            style: TextStyle(
              color: Colors.black,
              fontSize: 15,
            ),
            overflow: TextOverflow.ellipsis,
          ),
          SizedBox(
            height: 2,
          ),
          Expanded(
            child: Text.rich(
              TextSpan(
                children: [
                  WidgetSpan(
                    child: Icon(
                      Icons.filter_tilt_shift,
                      color: Colors.orange,
                      size: 17,
                    ),
                  ),
                  TextSpan(
                    text: " 9999 ",
                    style: TextStyle(
                      color: Colors.red,
                      fontSize: 17,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  TextSpan(
                    text: '￥19.8',
                    style: TextStyle(
                      color: Colors.grey,
                      fontSize: 11,
                      decoration: TextDecoration.lineThrough,
                      decorationColor: Colors.grey,
                    ),
                  ),
                ],
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
        ],
      ),
    ),
  );
}

///边玩边赚
Widget _moneyView(TaskState state, Dispatch dispatch, ViewService viewService) {
  bool _handleScrollNotification(ScrollNotification notification) {
    final ScrollMetrics metrics = notification.metrics;
    double alignmentY = -1 + (metrics.pixels / metrics.maxScrollExtent) * 2;
    dispatch(TaskActionCreator.upAlignmentY(alignmentY));
    return true;
  }

  return Container(
    margin: EdgeInsets.symmetric(horizontal: 10),
    padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
    decoration: BoxDecoration(
      borderRadius: BorderRadius.all(Radius.circular(10)),
      color: Colors.white,
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: EdgeInsets.only(top: 0),
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Colors.amber[100], Colors.amber[50]],
            ),
            borderRadius: BorderRadius.circular(8),
          ),
          child: Text(
            '边玩边赚',
            style: TextStyle(
              fontSize: 17,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        Container(
          height: 105,
          margin: EdgeInsets.only(top: 10),
          color: Colors.white,
          child: NotificationListener<ScrollNotification>(
            onNotification: _handleScrollNotification,
            child: Stack(
              alignment: Alignment.bottomCenter,
              children: <Widget>[
                ListView.separated(
                  // reverse: false,
                  scrollDirection: Axis.horizontal,
                  itemCount: 50,
                  separatorBuilder: (BuildContext context, int index) {
                    return Container(
                      width: 0.3,
                      color: Colors.grey,
                      margin: EdgeInsets.only(top: 25, bottom: 40),
                    );
                  },
                  itemBuilder: (context, index) {
                    return _moneyItem(index);
                  },
                ),
                Container(
                  width: 20,
                  height: 4,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(4)),
                    color: Colors.grey,
                  ),
                  alignment: Alignment(state.alignmentY, 1),
                  child: Container(
                    height: 4,
                    width: 12,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(4)),
                      color: Colors.red,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  );
}

Widget _moneyItem(int index) {
  return GestureDetector(
    onTap: () {},
    child: Container(
      width: 100,
      child: Column(
        // crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Image.asset(
            index % 2 == 0
                ? 'assets/images/user_center/tiantianhongbao.png'
                : 'assets/images/user_center/yunfadan.png',
            width: 60,
            height: 60,
          ),
          Text(
            index % 2 == 0 ? '红包大富翁' : '做任务赚钱',
            style: TextStyle(
              color: Colors.black,
              fontSize: 15,
            ),
            overflow: TextOverflow.ellipsis,
          ),
        ],
      ),
    ),
  );
}

///每日推荐
Widget _recommendView(
    TaskState state, Dispatch dispatch, ViewService viewService) {
  double cellWidth = ((MediaQuery.of(viewService.context).size.width - 30) / 2);
  double desiredCellHeight = cellWidth + 5 + 50 + 26 + 40 + 22 + 15;
  double childAspectRatio = cellWidth / desiredCellHeight;
  return GridView.builder(
    shrinkWrap: true,
    physics: NeverScrollableScrollPhysics(),
    padding: EdgeInsets.fromLTRB(10, 5, 10, 0),
    itemCount: gridViewList.length,
    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 2,
      crossAxisSpacing: 10,
      mainAxisSpacing: 10,
      childAspectRatio: childAspectRatio,
    ),
    itemBuilder: (BuildContext context, int index) {
      return Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(10)),
          color: Colors.white,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            ClipRRect(
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10), topRight: Radius.circular(10)),
              child: Image.network(
                index % 2 == 0
                    ? "https://img.gzzhitu.com/zhitu-api/1622894340675195.jpg"
                    : "https://img.gzzhitu.com/zhitu-api/1622894340689970.jpg",
                height:
                    (MediaQuery.of(viewService.context).size.width - 30) / 2,
                width: (MediaQuery.of(viewService.context).size.width - 30) / 2,
                fit: BoxFit.cover,
              ),
            ),
            SizedBox(
              height: 5,
            ),
            Container(
              height: 50,
              padding: EdgeInsets.symmetric(horizontal: 10),
              child: Text.rich(
                TextSpan(
                  children: [
                    WidgetSpan(
                      child: Image.asset(
                        index % 2 == 0
                            ? "assets/images/user_center/user_order_shop_icon_jd.png"
                            : "assets/images/user_center/user_order_shop_icon_tb.png",
                        width: 50,
                        height: 20,
                      ),
                    ),
                    TextSpan(
                      text: '光明 优加纯牛奶250ml*16盒/礼盒装 中华老字号光明',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ],
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            Flexible(
              child: Container(
                height: 26,
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(
                        text: '￥',
                        style: TextStyle(
                          color: Colors.red,
                          fontSize: 14,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                      TextSpan(
                        text: '9.9 ',
                        style: TextStyle(
                          color: Colors.red,
                          fontSize: 25,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      TextSpan(
                        text: '￥49.9',
                        style: TextStyle(
                          color: Colors.grey,
                          fontSize: 14,
                          decoration: TextDecoration.lineThrough,
                          decorationColor: Colors.grey,
                        ),
                      ),
                    ],
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ),
            Flexible(
              child: Container(
                height: 40,
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Text(
                  '已售294879',
                  style: TextStyle(
                    color: Colors.grey,
                    fontSize: 14,
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ),
            Container(
              height: 22,
              padding: EdgeInsets.symmetric(horizontal: 10),
              child: Row(
                children: [
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 3, vertical: 2),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(5),
                        color: Colors.red),
                    child: Text(
                      '满60减30',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 13,
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 5,
                  ),
                  Flexible(
                    child: UnconstrainedBox(
                      //“去除”父级限制
                      child: Container(
                        padding:
                            EdgeInsets.symmetric(horizontal: 10, vertical: 1),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(5),
                            color: Colors.red[100]),
                        child: Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                  text: "预估赚",
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontSize: 11,
                                      fontWeight: FontWeight.bold)),
                              TextSpan(
                                text: "￥",
                                style: TextStyle(
                                  color: Colors.red,
                                  fontSize: 11,
                                ),
                              ),
                              TextSpan(
                                text: "1.26",
                                style: TextStyle(
                                    color: Colors.red,
                                    fontSize: 14,
                                    fontWeight: FontWeight.bold),
                              ),
                            ],
                          ),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      );
    },
  );
}
